#pragma once

#include <iostream>
#include <ctemplate/template.h>

#include "oj_model.hpp"

namespace ns_view
{

    using namespace ns_model;

    class view
    {
        const std::string template_path = "./template_html/";

    public:
        bool AllExpandHtml(const std::vector<struct Question> &all, std::string *html)
        {
            // 确定文件位置
            std::string src_path = template_path + "all_questions.html";
            // 创建字典
            ctemplate::TemplateDictionary root("all_questions");
            for (const auto &q : all)
            {
                ctemplate::TemplateDictionary *one = root.AddSectionDictionary("questions_list");
                one->SetValue("number", q.number);
                one->SetValue("title", q.title);
                one->SetValue("star", q.star);
            }
            // 确认渲染文件
            ctemplate::Template *a = ctemplate::Template::GetTemplate(src_path, ctemplate::DO_NOT_STRIP);
            // 渲染
            a->Expand(html, &root);
            return true;
        }

        bool OneExpandHtml(const Question &q, std::string *html)
        {
            // 确定文件位置
            std::string src_path = template_path + "one_questions.html";
            // 创建字典
            ctemplate::TemplateDictionary root("one_questions");
            root.SetValue("number", q.number);
            root.SetValue("title", q.title);
            root.SetValue("star", q.star);
            root.SetValue("precode", q.header);
            root.SetValue("desc", q.desc);
            // 确认渲染文件
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_path, ctemplate::DO_NOT_STRIP);
            // 渲染
            tpl->Expand(html, &root);
            return true;
        }

        
    };
}